package zone.czh.woi.woim.protocol.selector;

import io.netty.channel.ChannelPipeline;
import zone.czh.woi.protocol.protocol.Payload;
import zone.czh.woi.woim.base.constant.ChannelCst;
import zone.czh.woi.woim.base.channel.protocol.selector.ProtocolSelector;
import zone.czh.woi.woim.server.constant.AttributeKeyConstant;
import zone.czh.woi.woim.server.util.AttributeKeyUtil;

/**
*@ClassName: DefaultServerProtocolSelector
*@Description: None
*@author woi
*/
public class DefaultServerProtocolSelector implements ProtocolSelector {
    @Override
    public String select(ChannelPipeline pipeline, Payload payload) {
        String protocolName = null;
        String protocol = AttributeKeyUtil.get(pipeline.channel(),
                AttributeKeyConstant.PROTOCOL, String.class);
        if (protocol!=null){
            return protocol;
        }
        Integer channelType = AttributeKeyUtil.get(pipeline.channel(),
                AttributeKeyConstant.CHANNEL_TYPE, Integer.class);
        if (channelType==null){
            switch (channelType){
                case ChannelCst.Type.ANDROID:
                case ChannelCst.Type.IOS:
                case ChannelCst.Type.DESKTOP:
                    protocolName = "protobuf";
                    break;
                case ChannelCst.Type.WEB:
                    protocolName = "web_socket";
                    break;
            }
        }else {

        }

        return protocolName;
    }
}
